import java.util.ArrayList;

public class GenericStack<E> implements GenericStackInterface<E> {
    /**
     * The list of objects of this stack
     */
    private java.util.ArrayList<E> list;

	public GenericStack() {
		list = new ArrayList<E>();
	}

	/**
     * Add new Top item. and the length of list  + 1
     *
     * @param newTopItem new top item.
     */
    @Override
    public void push(E newTopItem) {
		list.add(newTopItem);
    }

    /**
     * Pop a top item.and the length of list -1
     *
     * @return top item.
     */
    @Override
    public E pop() {
		E e = list.get(list.size() - 1);
		list.remove(e);
		return e;
    }

    /**
     * Get a top item,but the length of list do not change .no item need move.
     *
     * @return top item.
     */
    @Override
    public E peek() {
        return list.get(list.size());
    }

    /**
     * Return true if the list have not any item.
     *
     * @return Return true if the list have not any item.
     */
    @Override
    public boolean isEmpty() {
        return list.size() <= 0;
    }
}
